<?php

namespace app\admin\model;

use think\Model;

class DormitoryBuilding extends Model
{
    // 表名
    protected $name = 'dormitory_building';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = false;

    public function creator()
    {
        return $this->belongsTo('Admin', 'creator_id', 'id', [], 'LEFT')->field('id,nickname');
    }

    public function garden()
    {
        return $this->belongsTo('DormitoryGarden', 'garden_number', 'number', [], 'LEFT')->field('id,name,number');
    }

    public function getDormTypeTextAttr($value, $data)
    {
        return isset(DormitoryDorm::$typeList[$data['dorm_type']]) ? DormitoryDorm::$typeList[$data['dorm_type']] : '';
    }

}
